package action;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class UserPermissionFilter extends HttpServlet implements Filter {

	protected FilterConfig filterConfig = null;

	public void destroy() {
		this.filterConfig = null;
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
		try {
			HttpServletRequest req = (HttpServletRequest) request;
			//String userName = (String) req.getSession().getAttribute("LOGIN_USER_Name");
			String type = (String) req.getSession().getAttribute("LOGIN_USER_TYPE");
			//System.out.println("ddddd"+userName);
			if (!type.equals("1")) {
				//System.out.println("ddddd222222222222222"+req.getServletPath());

				HttpServletResponse rep = (HttpServletResponse) response;
				//req.getSession().setAttribute("PRE_URL",req.getServletPath());
				//req.getSession().setAttribute("PRE_URL",""+req.getHeader("Referer"));
				rep.sendRedirect(req.getContextPath()+"/user/Login.jsp");
			} else {
				//System.out.println("ddddd11111111111111111");
				filterChain.doFilter(request, response);
			}
		} catch (Exception e) {
		}
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		this.filterConfig = filterConfig;
	}

	public FilterConfig getFilterConfig() {
		return filterConfig;
	}

	public void setFilterConfig(FilterConfig filterConfig) {
		this.filterConfig = filterConfig;
	}

}
